#ifndef CBKEYBINDER_H
#define CBKEYBINDER_H

#if defined(__GNUG__) && !defined(__APPLE__)
#pragma interface "cbkeybinder.h"
#endif
#include <wx/string.h>
#include <wx/timer.h>
#include "M_Code_plugin.h"
#include "configurationpanel.h"
#include "keybinder.h"
#define VERSION "1.0.51 2015/08/21"

class MyDialog;
class wxKeyConfigPanel;
class wxKeyProfileArray;
class wxWindow;
class wxEvent;
class wxMenuBar;
class wxLogWindow;
class wxArrayPtrVoid;

class cbKeyBinder : public M_Code_Plugin {
    friend class MyDialog;
  public:
    cbKeyBinder();
    ~cbKeyBinder();
    int GetConfigurationGroup() const { return cgEditor; }
    cbConfigurationPanel* GetConfigurationPanel( wxWindow* parent );
    void BuildMenu( wxMenuBar* menuBar );
    void BuildModuleMenu( const ModuleType type, wxMenu* menu, const FileTreeData* data = 0 );
    bool BuildToolBar( wxToolBar* toolBar );
    void OnAttach();
    void OnRelease( bool appShutDown );
    wxKeyProfileArray* m_pKeyProfArr;
    wxMenuBar* m_pMenuBar;
    wxString m_sConfigFolder;
    wxString m_sExecuteFolder;
    wxString m_sDataFolder;
    wxString m_sKeyFilename;
    wxString m_sKeyFilePath;
    wxString m_OldKeyFilename;
    bool m_bBound;
    void UpdateArr( wxKeyProfileArray &r );
    void Rebind( bool update = true );
    cbConfigurationPanel* OnKeyConfig( wxWindow* parent );
    void OnKeyConfigDialogDone( MyDialog* dlg );
    void OnSave( bool backitup = false );
    void OnLoad();
    int EnableMerge( bool allow );
    int IsEnabledMerge() const {return m_mergeEnabled;}
    bool IsMerging() const {return m_bMerging;}
    void IsMerging( bool state ) {m_bMerging = state;}
    bool VerifyKeyBind( const wxString& strKeyCode, const int numShortcuts );
    int RemoveKeyBindingsFor( const wxString& strKeyCode, wxKeyProfile* pkp );
  protected:
    wxADD_KEYBINDER_SUPPORT();
  private:
    void OnProjectOpened( CodeBlocksEvent& event );
    void OnProjectActivated( CodeBlocksEvent& event );
    void OnProjectClosed( CodeBlocksEvent& event );
    void OnProjectFileAdded( CodeBlocksEvent& event );
    void OnProjectFileRemoved( CodeBlocksEvent& event );
    void OnEditorOpen( CodeBlocksEvent& event );
    void OnEditorClose( CodeBlocksEvent& event );
    void OnMergeTimer( wxTimerEvent& event );
    void OnAppStartupDone( CodeBlocksEvent& event );
    void AttachEditor( wxWindow* pEditor );
    void OnWindowCreateEvent( wxEvent& event );
    void OnWindowDestroyEvent( wxEvent& event );
    void DetachEditor( wxWindow* pWindow, bool deleteEvtHandler = true );
    void MergeDynamicMenus();
    void OnAppStartShutdown( CodeBlocksEvent& event );
    void OnIdle( wxIdleEvent& event );
    void OnTimerAlarm( wxTimerEvent& event );
    void OnMenuBarModify( CodeBlocksEvent& event );
    wxString FindAppPath( const wxString& argv0, const wxString& cwd, const wxString& appVariableName );
    void MergeAcceleratorTable( const bool mergeAccelTable = false );
    int  RemoveCopyPasteBindings( wxKeyProfile* pkp );
    wxWindow*       pcbWindow;              //main app window
    wxArrayPtrVoid  m_EditorPtrs;           //attached editor windows
    bool            bKeyFileErrMsgShown;
    int             m_MenuModifiedByMerge;  //menu dynamically modified
    int             m_mergeEnabled;         //merging menus allowed
    bool            m_bMerging;             //merging menus active
    bool            m_menuPreviouslyBuilt;
  private:
    wxTimer         m_Timer;
    void    StartMergeTimer( int secs ) { m_Timer.Start( secs * 1000, wxTIMER_ONE_SHOT ); }
    void    StopMergeTimer() { m_Timer.Stop();}
    bool    m_bTimerAlarm;
    bool    m_bAppShutDown;
    bool    m_bConfigBusy;
    DECLARE_EVENT_TABLE()

};

class MyDialog : public cbConfigurationPanel {
  public:
    wxKeyConfigPanel *m_p;
  public:
    MyDialog( cbKeyBinder* binder, wxKeyProfileArray &arr, wxWindow *parent, const wxString& title, int );
    ~MyDialog();
    wxString GetTitle() const { return _( "Keyboard shortcuts" ); }
    wxString GetBitmapBaseName() const { return _T( "onekeytobindthem" ); }
    void OnApply();
    void OnCancel() {}
  private:
    cbKeyBinder* m_pBinder;
    DECLARE_EVENT_TABLE()
};

#endif
